namespace :db do
  namespace :seed do
    desc "Seeds the bare minumum data needed for the app"
    task :bare => :environment do
      seed_dir File.join('db', 'seed', 'base')
    end
  end

  def seed_dir(dir)
    require 'active_record/fixtures'

    puts "-- seeding files in #{dir}"
    puts "   -> %.4fs" % Benchmark.realtime {
      Dir[File.join(dir, '*.rb')].each { |file| load file }
      table_names = Dir[File.join(dir, '*.{yml,csv}')].map { |file| File.basename(file, '.*') }
      Fixtures.create_fixtures(dir, table_names)
    }
  end

  task :seed => 'seed:bare'
end